<template>
  <div class="rights_container">
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>权限管理</el-breadcrumb-item>
      <el-breadcrumb-item>权限列表</el-breadcrumb-item>
    </el-breadcrumb>

    <el-card>
      <el-table :data="newRightsList" style="width: 100%" border stripe>
        <el-table-column type="index" width="70" label="序号"></el-table-column>
        <el-table-column prop="authName" label="路径"></el-table-column>
        <el-table-column prop="path" label="路径"></el-table-column>
        <el-table-column prop="level" label="权限等级">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.level==0">一级</el-tag>
            <el-tag type="success" v-if="scope.row.level==1">二级</el-tag>
            <el-tag type="warning" v-if="scope.row.level==2">三级</el-tag>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <el-pagination
        @current-change="handleCurrentChange"
        :current-page="pagenum"
        :page-sizes="[10]"
        layout="total, prev, pager, next, jumper"
        :total="48"
      ></el-pagination>
    </el-card>
  </div>
</template>

<script>
export default {
  data() {
    return {
      rightsList: [],
      pagenum: 1,
      newRightsList: []
    }
  },
  created() {
    this.getRightsList()
  },
  watch: {
    pagenum: function() {
      this.newRightsList = this.rightsList.slice(
        (this.pagenum - 1) * 10,
        this.pagenum * 10
      )
    }
  },
  methods: {
    async getRightsList() {
      var res = await this.$http.get(`rights/list`).then(res => {
        if (res.data.meta.status != 200) {
          console.log('获取数据失败')
        }
        this.rightsList = res.data.data
        this.newRightsList = res.data.data.slice(0, 10)
      })
    },
    handleCurrentChange(val) {
      this.pagenum = val
    }
  }
}
</script>

<style lang="less" scoped>
.rights_container {
  .el-card {
    margin-top: 20px;
  }
}
</style>